﻿using BalloonCS;
using OrderSystem.Common;
using OrderSystem.DataAccess;
using OrderSystem.SystemFramework;
using OrderSystem.Templet;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;

namespace OrderSystem
{
    public partial class FormUpdateTechnics : FormTemplet
    {
        private string _orderItemID = null;

        private string _sProductType = "";

        private int _nProductTypeID = -1;

        private string _sUnit = "";

        private string _sProductCode = "";

        private string _sWidth = "";

        private string _sSubtenseOfWidth = "";

        private string _sHeight = "";

        private string _sSubtenseOfHeight = "";

        private string _sQuantity = "";

        private string _sPrice = "";

        private string _sRemark = "";

        private MessageBalloon _mb;

        private FormOrderInfo frmOrderInfo;

        private Color errorColor = Color.FromArgb(199, 200, 203);

        private DataTable _dtTechnics = null;

        private int nRowIndex = 0;

        private int nColumnIndex = 0;

        public FormUpdateTechnics()
        {
            this.InitializeComponent();
            ToolStripMenuItem value = new ToolStripMenuItem("一长边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("一短边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("两长边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("两短边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("两长边+一短边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("两短边+一长边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("一长边+一短边", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
            value = new ToolStripMenuItem("周长", null, new EventHandler(this.ContextMenu_Click));
            this.contextMenuStrip1.Items.Add(value);
        }

        public FormUpdateTechnics(string orderItemID, FormOrderInfo frmOrderInfo) : this()
        {
            this._orderItemID = orderItemID;
            this.frmOrderInfo = frmOrderInfo;
            DataSet dataSet = null;
            OrderItems orderItems = new OrderItems();
            try
            {
                dataSet = orderItems.LoadOrderItem(this._orderItemID);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            orderItems.Dispose();
            if (dataSet != null)
            {
                if (dataSet.Tables.Count == 2)
                {
                    if (dataSet.Tables[0].Rows.Count > 0)
                    {
                        this._nProductTypeID = Convert.ToInt32(dataSet.Tables[0].Rows[0]["产品类型ID"]);
                        this._sProductType = dataSet.Tables[0].Rows[0]["产品类型"].ToString();
                        this._sUnit = dataSet.Tables[0].Rows[0]["类型单位"].ToString();
                        this._sProductCode = dataSet.Tables[0].Rows[0]["产品编号"].ToString();
                        this._sWidth = dataSet.Tables[0].Rows[0]["宽"].ToString();
                        this._sSubtenseOfWidth = dataSet.Tables[0].Rows[0]["宽(短边)"].ToString();
                        this._sHeight = dataSet.Tables[0].Rows[0]["高"].ToString();
                        this._sSubtenseOfHeight = dataSet.Tables[0].Rows[0]["高(短边)"].ToString();
                        this._sQuantity = dataSet.Tables[0].Rows[0]["产品数量"].ToString();
                        this._sPrice = dataSet.Tables[0].Rows[0]["价格"].ToString();
                        this._sRemark = dataSet.Tables[0].Rows[0]["产品备注"].ToString();
                        this._dtTechnics = dataSet.Tables[1];
                    }
                }
                else
                {
                    MessageBox.Show("订单中可能没有这条数据信息！", "提示！", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }

        private void FormAddOrderItem_Load(object sender, EventArgs e)
        {
            this.dgProductTechnics.Columns.Add("technicsName", "工艺名称");
            this.dgProductTechnics.Columns[0].ReadOnly = true;
            this.dgProductTechnics.Columns.Add("technicsQuantity", "数量");
            this.dgProductTechnics.Columns[1].ReadOnly = true;
            this.dgProductTechnics.Columns.Add("technicsUnitPrice", "单价");
            this.dgProductTechnics.Columns[2].ReadOnly = true;
            this.dgProductTechnics.Columns.Add("technicsRemark", "备注");
            this.dgProductTechnics.Columns[3].ReadOnly = true;
            this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[0].Cells[0];
            for (int i = 0; i < this.dgProductTechnics.Columns.Count; i++)
            {
                this.dgProductTechnics.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic;
            }
            for (int i = 0; i < this._dtTechnics.Rows.Count; i++)
            {
                this.dgProductTechnics.Rows.Add();
                this.dgProductTechnics.Rows[i].Cells[0].Value = this._dtTechnics.Rows[i][0].ToString();
                this.dgProductTechnics.Rows[i].Cells[1].Value = this._dtTechnics.Rows[i][1].ToString();
                this.dgProductTechnics.Rows[i].Cells[2].Value = this._dtTechnics.Rows[i][2].ToString();
                this.dgProductTechnics.Rows[i].Cells[3].Value = this._dtTechnics.Rows[i][3].ToString();
            }
            this.dgProductTechnics.AutoResizeColumns();
        }

        private void FormUpdateOrderItem_Activated(object sender, EventArgs e)
        {
            base.WindowState = FormWindowState.Normal;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            int i = 0;
            while (i < this.dgProductTechnics.Rows.Count)
            {
                this.dgProductTechnics.Rows[i].Cells[0].Value = CommonMethod.Fun1((this.dgProductTechnics.Rows[i].Cells[0].Value == null) ? "" : this.dgProductTechnics.Rows[i].Cells[0].Value.ToString());
                this.dgProductTechnics.Rows[i].Cells[1].Value = CommonMethod.Fun1((this.dgProductTechnics.Rows[i].Cells[1].Value == null) ? "" : this.dgProductTechnics.Rows[i].Cells[1].Value.ToString());
                this.dgProductTechnics.Rows[i].Cells[2].Value = CommonMethod.Fun1((this.dgProductTechnics.Rows[i].Cells[2].Value == null) ? "" : this.dgProductTechnics.Rows[i].Cells[2].Value.ToString());
                this.dgProductTechnics.Rows[i].Cells[3].Value = CommonMethod.Fun1((this.dgProductTechnics.Rows[i].Cells[3].Value == null) ? "" : this.dgProductTechnics.Rows[i].Cells[3].Value.ToString());
                if (this.dgProductTechnics.Rows[i].Cells[0].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[1].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[2].Value.ToString() == "")
                {
                    break;
                }
                if (this.dgProductTechnics.Rows[i].Cells[0].Value.ToString().Trim().Length > 32 || this.dgProductTechnics.Rows[i].Cells[0].Value.ToString().Trim().Length < 1)
                {
                    this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[i].Cells[0];
                    this._mb = new MessageBalloon();
                    this._mb.Parent = this.cbTechnicsName;
                    this._mb.Title = "提示！";
                    this._mb.TitleIcon = TooltipIcon.Info;
                    this._mb.Text = "工艺名称 格式不正确，字符太长或是空，应等于1-32个字符！";
                    BalloonAlignment align = BalloonAlignment.RightMiddle;
                    this._mb.Align = align;
                    this._mb.CenterStem = false;
                    this._mb.UseAbsolutePositioning = false;
                    this._mb.Show();
                }
                else if (!Regex.IsMatch(this.dgProductTechnics.Rows[i].Cells[1].Value.ToString().Trim(), "^(([0-9]{1,8})|([0-9]{1,}\\.[0-9]{1,4}))$") || Convert.ToDouble(this.dgProductTechnics.Rows[i].Cells[1].Value.ToString().Trim()) <= 0.0)
                {
                    this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[i].Cells[1];
                    this._mb = new MessageBalloon();
                    this._mb.Parent = this.txt;
                    this._mb.Title = "提示！";
                    this._mb.TitleIcon = TooltipIcon.Info;
                    this._mb.Text = "数量 格式不正确，此处应该为大于零的数字，如有小数，最大为4位小数！";
                    BalloonAlignment align = BalloonAlignment.RightMiddle;
                    this._mb.Align = align;
                    this._mb.CenterStem = false;
                    this._mb.UseAbsolutePositioning = false;
                    this._mb.Show();
                }
                else if (!Regex.IsMatch(this.dgProductTechnics.Rows[i].Cells[2].Value.ToString().Trim(), "^(([0-9]{1,8})|([0-9]{1,}\\.[0-9]{1,4}))$") || Convert.ToDouble(this.dgProductTechnics.Rows[i].Cells[1].Value.ToString().Trim()) < 0.0)
                {
                    this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[i].Cells[2];
                    this._mb = new MessageBalloon();
                    this._mb.Parent = this.txt;
                    this._mb.Title = "提示！";
                    this._mb.TitleIcon = TooltipIcon.Info;
                    this._mb.Text = "单价 格式不正确，此处应该为大于零的数字，如有小数，最大为4位小数！";
                    BalloonAlignment align = BalloonAlignment.RightMiddle;
                    this._mb.Align = align;
                    this._mb.CenterStem = false;
                    this._mb.UseAbsolutePositioning = false;
                    this._mb.Show();
                }
                else
                {
                    if (this.dgProductTechnics.Rows[i].Cells[3].Value.ToString().Length <= 32)
                    {
                        i++;
                        continue;
                    }
                    this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[i].Cells[3];
                    this._mb = new MessageBalloon();
                    this._mb.Parent = this.txt;
                    this._mb.Title = "提示！";
                    this._mb.TitleIcon = TooltipIcon.Info;
                    this._mb.Text = "工艺备注 格式不正确，字符太长，应在 32 个字符之内！";
                    BalloonAlignment align = BalloonAlignment.RightMiddle;
                    this._mb.Align = align;
                    this._mb.CenterStem = false;
                    this._mb.UseAbsolutePositioning = false;
                    this._mb.Show();
                }
                return;
            }
            OrderItems orderItems = new OrderItems();
            bool flag = false;
            try
            {
                flag = orderItems.UpdateProductTechnics(this._orderItemID, this.cbUpdateWay.Checked ? "O" : "P", LoginInfo.OperatorID, this.GetTechnicsXMLDocument());
            }
            catch (SqlException ex)
            {
                int number = ex.Number;
                if (number != 50001)
                {
                    switch (number)
                    {
                        case 50100:
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.frmOrderInfo.chkLockedData.Checked = true;
                            break;
                        case 50101:
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.frmOrderInfo.chkCancelled.Checked = true;
                            break;
                        case 50102:
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.frmOrderInfo.menuEditData.Checked = false;
                            break;
                        case 50103:
                            MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            break;
                        default:
                            if (number != 50200)
                            {
                                MessageBox.Show(ex.Message + "\r\n\r\n或者是连接数据库的通道出现故障，请检查！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                            else
                            {
                                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            break;
                    }
                }
                else
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            orderItems.Dispose();
            if (flag)
            {
                if (!this.cbUpdateWay.Checked)
                {
                    this.frmOrderInfo.ReloadOrderItemsForUpdate(this._orderItemID, this.GetTechnics());
                }
                else
                {
                    this.frmOrderInfo.RefreshItems();
                }
                base.Close();
                return;
            }
        }

        private string GetTechnics()
        {
            string text = "";
            for (int i = 0; i < this.dgProductTechnics.Rows.Count; i++)
            {
                if (this.dgProductTechnics.Rows[i].Cells[0].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[1].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[2].Value.ToString() == "")
                {
                    break;
                }
                if (text.Length > 0)
                {
                    string text2 = text;
                    text = string.Concat(new string[]
                    {
                        text2,
                        "/",
                        this.dgProductTechnics.Rows[i].Cells[0].Value.ToString(),
                        "(数量:",
                        this.dgProductTechnics.Rows[i].Cells[1].Value.ToString(),
                        ")"
                    });
                }
                else
                {
                    text = this.dgProductTechnics.Rows[i].Cells[0].Value.ToString() + "(数量:" + this.dgProductTechnics.Rows[i].Cells[1].Value.ToString() + ")";
                }
            }
            return text;
        }

        private string GetTechnicsXMLDocument()
        {
            XmlDocument xmlDocument = new XmlDocument();
            XmlNode xmlNode = xmlDocument.CreateElement("technics");
            xmlDocument.AppendChild(xmlNode);
            for (int i = 0; i < this.dgProductTechnics.Rows.Count; i++)
            {
                if (this.dgProductTechnics.Rows[i].Cells[0].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[1].Value.ToString() == "" && this.dgProductTechnics.Rows[i].Cells[2].Value.ToString() == "")
                {
                    break;
                }
                XmlNode xmlNode2 = xmlDocument.CreateElement("item");
                XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("sequenceCode");
                xmlAttribute.InnerText = i.ToString();
                xmlNode2.Attributes.Append(xmlAttribute);
                XmlAttribute xmlAttribute2 = xmlDocument.CreateAttribute("technicsName");
                xmlAttribute2.InnerText = this.dgProductTechnics.Rows[i].Cells[0].Value.ToString();
                xmlNode2.Attributes.Append(xmlAttribute2);
                XmlAttribute xmlAttribute3 = xmlDocument.CreateAttribute("quantity");
                xmlAttribute3.InnerText = this.dgProductTechnics.Rows[i].Cells[1].Value.ToString();
                xmlNode2.Attributes.Append(xmlAttribute3);
                XmlAttribute xmlAttribute4 = xmlDocument.CreateAttribute("unitPrice");
                xmlAttribute4.InnerText = this.dgProductTechnics.Rows[i].Cells[2].Value.ToString();
                xmlNode2.Attributes.Append(xmlAttribute4);
                XmlAttribute xmlAttribute5 = xmlDocument.CreateAttribute("remark");
                xmlAttribute5.InnerText = this.dgProductTechnics.Rows[i].Cells[3].Value.ToString();
                xmlNode2.Attributes.Append(xmlAttribute5);
                xmlNode.AppendChild(xmlNode2);
            }
            return xmlDocument.InnerXml;
        }

        private void ContextMenu_Click(object sender, EventArgs e)
        {
        }

        private void ConvertToBJ(object sender, EventArgs e)
        {
            ((Control)sender).ImeMode = ImeMode.Alpha;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void menuOk_Click(object sender, EventArgs e)
        {
            this.btnOk_Click(null, null);
        }

        private void btnHide_Click(object sender, EventArgs e)
        {
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dgProductTechnics.Rows.Count > 0)
            {
                foreach (DataGridViewRow dataGridViewRow in this.dgProductTechnics.SelectedRows)
                {
                    if (!dataGridViewRow.IsNewRow)
                    {
                        this.dgProductTechnics.Rows.Remove(dataGridViewRow);
                    }
                }
            }
        }

        private void btnMoveDown_Click(object sender, EventArgs e)
        {
            if (this.dgProductTechnics.Rows.Count >= 2 && this.dgProductTechnics.CurrentCell.RowIndex != this.dgProductTechnics.Rows.Count - 1)
            {
                int rowIndex = this.dgProductTechnics.CurrentCell.RowIndex;
                string text = (this.dgProductTechnics.Rows[rowIndex].Cells[0].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[0].Value.ToString();
                string text2 = (this.dgProductTechnics.Rows[rowIndex].Cells[1].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[1].Value.ToString();
                string text3 = (this.dgProductTechnics.Rows[rowIndex].Cells[2].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[2].Value.ToString();
                string text4 = (this.dgProductTechnics.Rows[rowIndex].Cells[3].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[3].Value.ToString();
                string text5 = (this.dgProductTechnics.Rows[rowIndex + 1].Cells[0].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex + 1].Cells[0].Value.ToString();
                string text6 = (this.dgProductTechnics.Rows[rowIndex + 1].Cells[1].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex + 1].Cells[1].Value.ToString();
                string text7 = (this.dgProductTechnics.Rows[rowIndex + 1].Cells[2].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex + 1].Cells[2].Value.ToString();
                string text8 = (this.dgProductTechnics.Rows[rowIndex + 1].Cells[3].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex + 1].Cells[3].Value.ToString();
                this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].SetValues(new object[]
                {
                    text5,
                    text6,
                    text7,
                    text8
                });
                this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex + 1].SetValues(new object[]
                {
                    text,
                    text2,
                    text3,
                    text4
                });
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[rowIndex + 1].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex];
                this.dgProductTechnics.Rows[rowIndex + 1].Selected = true;
            }
        }

        private void btnMoveUp_Click(object sender, EventArgs e)
        {
            if (this.dgProductTechnics.Rows.Count >= 2 && this.dgProductTechnics.CurrentCell.RowIndex != 0)
            {
                int rowIndex = this.dgProductTechnics.CurrentCell.RowIndex;
                string text = (this.dgProductTechnics.Rows[rowIndex].Cells[0].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[0].Value.ToString();
                string text2 = (this.dgProductTechnics.Rows[rowIndex].Cells[1].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[1].Value.ToString();
                string text3 = (this.dgProductTechnics.Rows[rowIndex].Cells[2].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[2].Value.ToString();
                string text4 = (this.dgProductTechnics.Rows[rowIndex].Cells[3].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex].Cells[3].Value.ToString();
                string text5 = (this.dgProductTechnics.Rows[rowIndex - 1].Cells[0].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex - 1].Cells[0].Value.ToString();
                string text6 = (this.dgProductTechnics.Rows[rowIndex - 1].Cells[1].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex - 1].Cells[1].Value.ToString();
                string text7 = (this.dgProductTechnics.Rows[rowIndex - 1].Cells[2].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex - 1].Cells[2].Value.ToString();
                string text8 = (this.dgProductTechnics.Rows[rowIndex - 1].Cells[3].Value == null) ? "" : this.dgProductTechnics.Rows[rowIndex - 1].Cells[3].Value.ToString();
                this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].SetValues(new object[]
                {
                    text5,
                    text6,
                    text7,
                    text8
                });
                this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex - 1].SetValues(new object[]
                {
                    text,
                    text2,
                    text3,
                    text4
                });
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[rowIndex - 1].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex];
                this.dgProductTechnics.Rows[rowIndex - 1].Selected = true;
            }
        }

        private void dgProductTechnics_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (!this.ckbDeleteTechnics.Checked)
            {
                int num = 0;
                int num2 = 0;
                int x = this.dgProductTechnics.Location.X;
                int y = this.dgProductTechnics.Location.Y;
                int x2 = this.dgProductTechnics.GetCellDisplayRectangle(this.dgProductTechnics.CurrentCell.ColumnIndex, this.dgProductTechnics.CurrentCell.RowIndex, false).X;
                int y2 = this.dgProductTechnics.GetCellDisplayRectangle(this.dgProductTechnics.CurrentCell.ColumnIndex, this.dgProductTechnics.CurrentCell.RowIndex, false).Y;
                int width = this.dgProductTechnics.GetCellDisplayRectangle(this.dgProductTechnics.CurrentCell.ColumnIndex, this.dgProductTechnics.CurrentCell.RowIndex, false).Width;
                int height = this.dgProductTechnics.GetCellDisplayRectangle(this.dgProductTechnics.CurrentCell.ColumnIndex, this.dgProductTechnics.CurrentCell.RowIndex, false).Height;
                if (this.dgProductTechnics.CurrentCell.ColumnIndex == 0)
                {
                    this.cbTechnicsName.Text = ((this.dgProductTechnics.CurrentCell.Value == null) ? "" : this.dgProductTechnics.CurrentCell.Value.ToString());
                    this.cbTechnicsName.Visible = true;
                    this.cbTechnicsName.Left = num + x + x2;
                    this.cbTechnicsName.Top = num2 + y + y2 + 1;
                    this.cbTechnicsName.Width = width;
                    this.cbTechnicsName.Height = height;
                    this.cbTechnicsName.Focus();
                }
                else
                {
                    this.cbTechnicsName.Hide();
                }
                if (this.dgProductTechnics.CurrentCell.ColumnIndex == 1 || this.dgProductTechnics.CurrentCell.ColumnIndex == 2 || this.dgProductTechnics.CurrentCell.ColumnIndex == 3)
                {
                    this.txt.Text = ((this.dgProductTechnics.CurrentCell.Value == null) ? "" : this.dgProductTechnics.CurrentCell.Value.ToString());
                    this.txt.Visible = true;
                    this.txt.Left = num + x + x2;
                    this.txt.Top = num + y + y2 + 1;
                    this.txt.Width = width;
                    this.txt.Height = height;
                    this.txt.Focus();
                    this.txt.SelectAll();
                }
                else
                {
                    this.txt.Hide();
                }
                if (this.dgProductTechnics.CurrentCell.ColumnIndex == 4)
                {
                    this.ckb.Checked = (this.dgProductTechnics.CurrentCell.Value != null && (bool)this.dgProductTechnics.CurrentCell.Value);
                    this.ckb.Visible = true;
                    this.ckb.Left = num + x + x2;
                    this.ckb.Top = num + y + y2;
                    this.ckb.Width = width;
                    this.ckb.Height = height;
                    this.ckb.Focus();
                }
                else
                {
                    this.ckb.Hide();
                }
            }
        }

        private void dgProductTechnics_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r' && this.nColumnIndex == this.dgProductTechnics.Columns.Count - 1 && this.nRowIndex < this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.nRowIndex + 1].Cells[0];
            }
            else if (e.KeyChar == '\r' && this.nColumnIndex == this.dgProductTechnics.Columns.Count - 1 && this.nRowIndex == this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.Rows.Add();
                this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 2].SetValues(new object[]
                {
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[0].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[1].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[2].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[3].Value,
                    true
                });
                this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].SetValues(new object[]
                {
                    null,
                    null,
                    null,
                    null,
                    false
                });
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[0];
                this.dgProductTechnics.AutoResizeColumns();
            }
        }

        private void dgProductTechnics_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                if (this.dgProductTechnics.CurrentCell.ColumnIndex == this.dgProductTechnics.Columns.Count - 1 && this.dgProductTechnics.CurrentCell.RowIndex < this.dgProductTechnics.Rows.Count - 1)
                {
                    this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex + 1].Cells[0];
                }
            }
            this.nRowIndex = this.dgProductTechnics.CurrentCell.RowIndex;
            this.nColumnIndex = this.dgProductTechnics.CurrentCell.ColumnIndex;
        }

        private void cbTechnicsName_TextChanged(object sender, EventArgs e)
        {
            this.dgProductTechnics.CurrentCell.Value = this.cbTechnicsName.Text;
        }

        private void cbTechnicsName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex + 1];
            }
        }

        private void cbTechnicsName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex + 1];
            }
            if (e.KeyCode == Keys.Left && this.dgProductTechnics.CurrentCell.RowIndex > 0)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex - 1].Cells[this.dgProductTechnics.Columns.Count - 1];
            }
            if (e.KeyCode == Keys.Left && this.dgProductTechnics.CurrentCell.RowIndex == 0 && this.dgProductTechnics.CurrentCell.ColumnIndex == 0)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[this.dgProductTechnics.Columns.Count - 1];
            }
        }

        private void txt_TextChanged(object sender, EventArgs e)
        {
            this.dgProductTechnics.CurrentCell.Value = this.txt.Text;
        }

        private void txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r' && this.dgProductTechnics.CurrentCell.ColumnIndex < this.dgProductTechnics.Columns.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex + 1];
            }
            else if (e.KeyChar == '\r' && this.dgProductTechnics.CurrentCell.ColumnIndex == this.dgProductTechnics.Columns.Count - 1 && this.dgProductTechnics.CurrentCell.RowIndex < this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex + 1].Cells[0];
            }
            else if (e.KeyChar == '\r' && this.dgProductTechnics.CurrentCell.ColumnIndex == this.dgProductTechnics.Columns.Count - 1 && this.dgProductTechnics.CurrentCell.RowIndex == this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.Rows.Add();
                this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 2].SetValues(new object[]
                {
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[0].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[1].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[2].Value,
                    this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[3].Value
                });
                DataGridViewRow arg_2C3_0 = this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1];
                object[] values = new object[4];
                arg_2C3_0.SetValues(values);
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.Rows.Count - 1].Cells[0];
                this.dgProductTechnics.AutoResizeColumns();
            }
        }

        private void txt_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right && this.dgProductTechnics.CurrentCell.RowIndex < this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex + 1].Cells[0];
            }
            if (e.KeyCode == Keys.Right && this.dgProductTechnics.CurrentCell.RowIndex == this.dgProductTechnics.Rows.Count - 1 && this.dgProductTechnics.CurrentCell.ColumnIndex == this.dgProductTechnics.Columns.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[0].Cells[0];
            }
            if (e.KeyCode == Keys.Left)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex - 1];
            }
            if (e.KeyCode == Keys.Up && this.dgProductTechnics.CurrentCell.RowIndex > 0)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex - 1].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex];
            }
            if (e.KeyCode == Keys.Down && this.dgProductTechnics.CurrentCell.RowIndex < this.dgProductTechnics.Rows.Count - 1)
            {
                this.dgProductTechnics.CurrentCell = this.dgProductTechnics.Rows[this.dgProductTechnics.CurrentCell.RowIndex + 1].Cells[this.dgProductTechnics.CurrentCell.ColumnIndex];
            }
        }

        private void ckbDeleteTechnics_CheckedChanged(object sender, EventArgs e)
        {
            if (this.ckbDeleteTechnics.Checked)
            {
                this.cbTechnicsName.Hide();
                this.txt.Hide();
                this.ckb.Hide();
            }
        }
    }
}
